﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibrarySync2.Business.FileSystem.Update;
using LibrarySync2.Business.FileSystem.Item;
using LibrarySync2.Common.Enum;
using LibrarySync2.Common.Interfaces;

namespace LibrarySync2.Business.FileSystem.Update
{
    public class FileSystemItemUpdate : IFileSystemItemUpdate
    {
        public MediaFileUpdateType MediaFileUpdateType { get; private set; }
        public IMediaFile MediaFile { get; private set; }
        public string RelativePath { get; private set; }

        internal FileSystemItemUpdate(MediaFileUpdateType mediaFileUpdateType, IMediaFile mediaFile)
            : this(mediaFileUpdateType, mediaFile, string.Empty)
        {
            //Do nothing more.
        }

        internal FileSystemItemUpdate(MediaFileUpdateType fileSystemItemUpdateType, IMediaFile fileSystemItem, string relativePath)
        {
            if (fileSystemItem == null)
                throw new ArgumentNullException("fileSystemItem");
            if (fileSystemItemUpdateType == MediaFileUpdateType.Replace && string.IsNullOrEmpty(relativePath))
                throw new ArgumentException("A relativePath must be provided when the FileSystemUpdateType is Replace.");

            MediaFileUpdateType = fileSystemItemUpdateType;
            MediaFile = fileSystemItem;
            RelativePath = (fileSystemItemUpdateType == MediaFileUpdateType.Add) ?
                fileSystemItem.RelativePath :
                relativePath;
        }
    }
}
